# -*- coding: UTF-8 -*-


class case:
    def __init__(self, caseid):
        self.caseid = caseid
        self.bugdetails = str()
        self.keywordslist = []
        self.screenshotslist = []
        self.tester = 0

    def print_case(self):
        print 'casID is: %s' % self.caseid
        print 'bugdetails: %s' % self.bugdetails
        print 'keywordslist: %d' % self.keywordslist.__len__()
        for i in self.keywordslist:
            print i
        print 'screenshotslist: %d' % self.screenshotslist.__len__()
        for i in self.screenshotslist:
            print i
        print 'tester: %s' % self.tester
        print ('')


class shot:
    def __init__(self, shotname):
        self.shotname = shotname
        self.keywords = []
        self.keylabels = []
        self.case = []

    def print_shot(self):
        print 'shotname: %s' % self.shotname
        print 'keywords: %d' % self.keywords.__len__()
        for i in self.keywords:
            print i


class single_img_train_result:
    def __init__(self, shotname):
        self.shotname = shotname
        self.true_label = []
        self.train_label = []

    def accuracy(self):
        TP = 0
        FP = 0
        FN = 0
        TN = 0
        for i in range(len(self.true_label)):
            if self.true_label[i] == 1:
                if self.train_label[i] == 1:
                    TP = TP + 1
                else:
                    FN = FN + 1
            if self.true_label[i] == 0:
                if self.train_label[i] == 1:
                    FP = FP + 1
                else:
                    TN = TN + 1
        precision = float(TP) / float(TP + FP)
        if TP == 0 and FN == 0:
            recall = 0
        else:
            recall = float(TP) / float(TP + FN)
        print 'shotname:' + str(self.shotname)
        print 'true:' + str(self.true_label)
        print 'train' + str(self.train_label)
        print 'precision: ' + str(precision)
        print 'recall: ' + str(recall)
        print ''
        return precision, recall


    def print_shot(self):
        print 'shotname: %s' % self.shotname
        print 'true_label: ' + self.true_label
        # print 'train_label: ' + self.train_label

class cluster:
    def __init__(self, clusterID):
        self.clusterID = clusterID
        self.shotsname = []
        self.shotsindex = []
        self.reportsindex = set()
        self.description = str()
        self.keywords = []
        # self.keywords_div_N = []

    def print_cluster(self):
        print 'clusterID: %s' % self.clusterID
        print 'shotsindex: %s' % self.shotsindex
        print 'shotsname: %s' % self.shotsname
        print 'reportsindex: %s' % self.reportsindex
        print 'description: %s' % self.description
        print 'keywords: count: %d' % len(self.keywords)
        for i in self.keywords:
            print '%s' % i,
        # print '\nkeywords_div_N: N: %d' % len(self.shotsindex)
        # for i in self.keywords_div_N:
        #     print '%s' % i,
        print ('\n')

